package Klassen;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class CSVReader {
	public static int[][] ReadCSV(String filename) throws IOException {
		int[][] result = new int[9][9];
		BufferedReader file = new BufferedReader(new FileReader(filename));
		String filerow = file.readLine();
		int y = 0;
		int x;
		while (filerow != null) {
			if (y > 8) {
				System.out.println("Error: CSVReader internal Error: y greater than 8");
				break;
			} else {
				filerow = filerow.replace("\"", "");
				String[] row = filerow.split(",");
				x = 0;
				for (String item : row) {
					if (x > 8) {
						System.out.println("Error: CSVReader internal Error: x greater than 8");
						break;
					} else {
						if(item.isEmpty() || item.contains("0")){
							x++;
						}else{
							result[y][x] = Integer.parseInt(item);
							x++;
						}
					}
				}
				filerow = file.readLine();
				y++;
			}
		}
		file.close();
		return result;
	}

}
